// src/main/java/com/csnf/mybatistest/HelloServlet.java
package com.csnf.mybatistest;

import com.csnf.dao.IStudentDao;
import com.csnf.dao.impl.StudentDaoImpl;
import com.csnf.entity.Student;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@WebServlet(name = "helloServlet", value = "/hello-servlet")
public class HelloServlet extends HttpServlet {
    private String message;

    public void init() {
        message = "Hello World!";
    }

    public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
        response.setContentType("text/html");
        IStudentDao studentDao = new StudentDaoImpl();
        List<Student> all = studentDao.findAll();
        request.setAttribute("students", all);
        request.getRequestDispatcher("/student.jsp").forward(request, response);
    }

    public void destroy() {
    }
}
